#!/bin/bash
#
# Copyright (C),2019-2020. 成都东志科技有限公司
# FileName: start.sh
# Author:   cj
# Date:     2020-08-12 16:14:11
# Description: //启动命令
# History: //修改记录 修改人姓名 修改时间 版本号 描述
# <canny>  <2021-08-12 16:14:11> <version>  cj <desc>
#
#

cd `dirname $0`

img_mvn="maven:3.3.3-jdk-8"                 # docker image of maven
m2_cache=~/.m2                              # the local maven cache dir
proj_home=$PWD                              # the project root dir
img_output="kl/scrm"         # output image tag

git pull  # should use git clone https://name:pwd@xxx.git

echo "use docker maven"
docker run --rm \
   -v $m2_cache:/root/.m2 \
   -v $proj_home:/usr/src/mymaven \
   -w /usr/src/mymaven $img_mvn mvn clean package -U -Dmaven.test.skip=true

sudo mv $proj_home/scrm/target/scrm-*.jar $proj_home/demo.jar # 兼容所有sh脚本
docker build -t $img_output .

mkdir -p $PWD/logs
chmod 777 $PWD/logs

# 删除容器
docker rm -f scrm &> /dev/null

version=`date "+%Y%m%d%H"`

# 启动镜像
docker run -d --restart=on-failure:5 --privileged=true \
    --net=host \
    -w /home \
    -v $PWD/logs:/home/logs \
    --name scrm kl/scrm \
    java \
        -Djava.security.egd=file:/dev/./urandom \
        -Duser.timezone=Asia/Shanghai \
        -XX:+PrintGCDateStamps \
        -XX:+PrintGCTimeStamps \
        -XX:+PrintGCDetails \
        -XX:+HeapDumpOnOutOfMemoryError \
        -Xloggc:logs/gc_${version}.log \
        -jar -Xms2048m -Xmx2048m /home/demo.jar --spring.profiles.active=dev\

docker logs -f scrm
